package com.app.base.dialog;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.app.base.R;


/**
 * Created by HJ on 2016-05-12.
 * 确认弹框Fragment
 */
public class ConfirmDialogFragment extends BaseDialogFragment {

    public final static int DIALOG_EXERCISE_EXIT = 1;
    private final static String KEY_FLAG = "key_flag";
    private int flag;
    private boolean cancelable;
    private Button btnOk;
    private Button btnCancel;
    private TextView content;
    private CommonDialogListener okListener;
    private CommonDialogListener cancelListener;
    private View view_middle;

    /**
     * 确认对话框的listener
     */
    public interface CommonDialogListener extends BaseDialogListener,View.OnClickListener{

    }

    public static ConfirmDialogFragment newInstance(int flag) {
        ConfirmDialogFragment fragment = new ConfirmDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_FLAG, flag);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        flag = getArguments().getInt(KEY_FLAG);
    }

    @Override
    public void onReceiveDialogListener(BaseDialogListener okListener, BaseDialogListener cancelListener) {
        if(okListener instanceof CommonDialogListener){
            this.okListener = (CommonDialogListener)okListener;
            this.cancelListener = (CommonDialogListener)cancelListener;
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder customBuilder = new AlertDialog.Builder(getActivity(),R.style.dialog);
//        View view = LayoutInflater.from(getActivity()).inflate(R.layout.custom_dialog,null);
//        btnOk = (Button)view.findViewById(R.id.dialog_ok);
//        btnCancel = (Button)view.findViewById(R.id.dialog_cancel);
//        content = (TextView)view.findViewById(R.id.tv_dialog_content);
//        btnOk.setOnClickListener(okListener);
//        btnCancel.setOnClickListener(cancelListener);
//        view_middle = view.findViewById(R.id.view_middle);
        selectDialog(flag);
//        customBuilder.setView(view);
        return customBuilder.create();
    }


    private void selectDialog(int flag) {
        switch (flag) {
            case DIALOG_EXERCISE_EXIT:
                content.setText("ok");
                btnOk.setText("cancel");
                break;
        }
    }

}
